package com.leo;

import javafx.application.Application;
import javafx.geometry.Bounds;
import javafx.geometry.Point2D;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

/**
 * @ClassName Summary
 * @Description 总结：坐标得问题
 * @Author wangss
 * @date 2020.05.26 22:13
 * @Version 1.0
 */
public class Summary2 extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane anchorPane = new AnchorPane();
        anchorPane.setStyle("-fx-background-color: #e7eeea");
        Scene scene = new Scene(anchorPane);

        Button button = new Button("button");

        HBox hBox = new HBox();
        hBox.setStyle("-fx-background-color: #08d4ff");
        hBox.setPrefWidth(200d);
        hBox.setPrefHeight(200d);
        hBox.getChildren().addAll(button);

        AnchorPane.setTopAnchor(hBox, 100d);
        AnchorPane.setLeftAnchor(hBox, 100d);
        anchorPane.getChildren().addAll(hBox);

        primaryStage.setScene(scene);
        primaryStage.setTitle("spinner");
        primaryStage.setWidth(625d);
        primaryStage.setHeight(500d);
        primaryStage.setResizable(false);
        primaryStage.show();

        // 以父组件得位置为相对位置
        System.out.println("左上角x = " + button.getLayoutX());
        System.out.println("左上角y = " + button.getLayoutY());

        Bounds bounds = button.getLayoutBounds();
        System.out.println("右下角x = " + bounds.getMaxX());
        System.out.println("右下角y = " + bounds.getMaxY());

        System.out.println("宽度 = " + bounds.getWidth());
        System.out.println("高度 = " + bounds.getHeight());

        Point2D point1 = button.localToParent(bounds.getMinX(), bounds.getMinY());

        System.out.println("在父组件hbox得坐标x为 = " + point1.getX());
        System.out.println("在父组件hbox得坐标y为 = " + point1.getY());

        Point2D point2 = button.localToScene(bounds.getMinX(), bounds.getMinY());

        System.out.println("相对组件scene得坐标x为 = " + point2.getX());
        System.out.println("相对组件scene得坐标y为 = " + point2.getY());

        Point2D point3 = button.localToScreen(bounds.getMinX(), bounds.getMinY());

        System.out.println("相对屏幕得坐标x为 = " + point3.getX());
        System.out.println("相对屏幕得坐标y为 = " + point3.getY());

    }
}
